package java6;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class LambdaQ5_2 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		PersonSortable3[] arr = new PersonSortable3[n];
		for (int i = 0; i < arr.length; i++) {
			String name = in.next();
			int age = in.nextInt();
			arr[i] = new PersonSortable3(name, age);
		}
		Comparator<PersonSortable3> nameComparator = (other1,other2) -> other1.getName().compareTo(other2.getName());
		Comparator<PersonSortable3> ageComparator = (other1,other2) -> other1.getAge() - other2.getAge();
		Arrays.sort(arr, nameComparator);
		System.out.println("NameComparator:sort");
		for (int i = 0; i < arr.length; i++) {
			System.out.println(arr[i]);
		}
		Arrays.sort(arr, ageComparator);
		System.out.println("AgeComparator:sort");
		for (int i = 0; i < arr.length; i++) {
			System.out.println(arr[i]);
		}
		System.out.println(Arrays.toString(nameComparator.getClass().getInterfaces()));
		System.out.println(Arrays.toString(ageComparator.getClass().getInterfaces()));
	}

}
class PersonSortable3 {
	private String name;
	private int age;

	public PersonSortable3(String name, int age) {
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return name + "-" + age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

}


